package com.temp.test;

import cn.hutool.core.util.IdUtil;
import com.constant.DbConfig;
import com.core.common.FnKit;
import com.core.dao.builder.InsertBuilder;
import com.core.excel.ExcelKit;
import com.module.material.entity.MaterialVO;
import com.module.material.service.MaterialService;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 读取Excel，生产其他出入库数据，同时生产出入库记录，但是不产生库存
 */
public class ReadExcelData {
    public static void main(String[] args) {
        String dir = "C:\\Users\\Administrator\\Desktop\\test\\";
        try {
            Map<Integer, List<Map<String, String>>> res = ExcelKit.analysis(dir + "1234.xlsx", 0);
            List<Map<String, String>> dataList = res.get(0);
            List<String> headList = new ArrayList<>();
            for (Map<String, String> b : dataList) {
                String myNo = nvl(b.get("NO"));
                InsertBuilder s4 = new InsertBuilder("a_test_material");
                s4.append("my_no", myNo);
                headList.add(s4.toString());
            }
            StringBuilder s2 = new StringBuilder();
            for (String s : headList) {
                if (s.length() > 1) {
                    s2.append(s.trim() + ";\n");
                } else {
                    s2.append("\n");
                }

            }
            Files.write(Paths.get(dir + "data" + System.currentTimeMillis() + ".txt"), s2.toString().getBytes());
            System.out.println("\n\n文件生产完成，数据行：" + headList.size());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    private static String nvl(String cellValue) {
        if (cellValue == null) {
            return "";
        }
        cellValue = cellValue.replace("\r", "");
        cellValue = cellValue.replace("\n", "");
        cellValue = cellValue.replace("\b", "");
        return cellValue;
    }


}
